import {defineStore} from "pinia"
import en from "element-plus/es/locale/lang/en"
import zhCn from "element-plus/es/locale/lang/zh-cn"
import YvEn from "/yvlocale/lang/en"
import YvZhCn from "/yvlocale/lang/zh-cn"

export default defineStore("app", {
    state() {
        const language = 'zh-cn'
        const sidebarStatus = "opened"
        const sidebar = {
            opened: sidebarStatus !== "closed",
            withoutAnimation: false,
        }
        const theme = 1
        const count = 0

        return {
            currentWhName: "",
            currentWhId: "",
            theme,
            count,
            language,
            sidebar,
            sidebarStatus
        }
    },
    getters: {
        /**
         * 根据语言标识读取对应的语言包
         */
        elLocale(state) {
            if (state?.language == "en") {
                return en;
            } else {
                return zhCn;
            }
        },

        yvLocale(state){
            if (state?.language == "en") {
                return YvEn;
            } else {
                return YvZhCn;
            }
        }
    },
    actions: {
        loadFromIndexDb(state) {
            this.$patch(state)
        },
        changeLanguage(val: string) {
            this.language = val;
        },
        toggleSidebar(withoutAnimation: boolean) {
            this.sidebar.opened = !this.sidebar.opened;
            this.sidebar.withoutAnimation = withoutAnimation;
            if (this.sidebar.opened) {
                this.sidebarStatus = "opened";
            } else {
                this.sidebarStatus = "closed";
            }
        },
        closeSideBar(withoutAnimation: boolean) {
            this.sidebar.opened = false;
            this.sidebar.withoutAnimation = withoutAnimation;
            this.sidebarStatus = "closed";
        },
        openSideBar(withoutAnimation: boolean) {
            this.sidebar.opened = true;
            this.sidebar.withoutAnimation = withoutAnimation;
            this.sidebarStatus = "opened";
        }
    }
})